﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
namespace AnyOffice.general.vehicle.checkup
{
    public partial class manage : ModulePage  
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = (Request.QueryString["refer"] != null) ? Request.QueryString["refer"].ToString() : "vehicle_wait.aspx";
            int usageId = (Request.QueryString["usage_id"] != null) ? int.Parse(Request.QueryString["usage_id"]) : 0;
            int operation = (Request.QueryString["operation"] != null) ? int.Parse(Request.QueryString["operation"]) : 1;
            VehicleUsageDao dao = new VehicleUsageDao();
            DataTable table = dao.SelectByUsageId(base.Conn, usageId);
            if (table.Rows.Count == 0)
            {
                this.litMessage.Text = base.ShowPrompt("无记录", url);
            }
            else
            {
                string str2 = table.Rows[0]["Proposer"].ToString();
                bool isSms = Convert.ToBoolean(table.Rows[0]["SmsRemind"].ToString());
                bool isMobile = Convert.ToBoolean(table.Rows[0]["MobileRemind"].ToString());
                SmsDao dao2 = new SmsDao();
                SmsData data = new SmsData();
                data.Type = 9;
                data.FromId = base.User.Identity.Name;
                data.SendTime = DateTime.Now;
                switch (operation)
                {
                    case 0:
                        dao.Manage(base.Conn, usageId, operation);
                        if (isSms || isMobile)
                        {
                            data.ToId = str2;
                            data.Content = "您的车辆申请已被撤销！";
                            data.Url = "/general/vehicle/apply/vehicle_wait.aspx";
                            dao2.BizSend(base.Conn, data, isSms, isMobile);
                        }
                        break;

                    case 1:
                        dao.Manage(base.Conn, usageId, operation);
                        if (isSms || isMobile)
                        {
                            data.ToId = str2;
                            data.Content = "您的车辆申请已被批准！";
                            data.Url = "/general/vehicle/apply/vehicle_ok.aspx";
                            dao2.BizSend(base.Conn, data, isSms, isMobile);
                        }
                        break;

                    case 2:
                        dao.Manage(base.Conn, usageId, operation);
                        if (isSms || isMobile)
                        {
                            data.ToId = str2;
                            data.Content = "您的车辆申请未被批准！";
                            data.Url = "/general/vehicle/apply/vehicle_no.aspx";
                            dao2.BizSend(base.Conn, data, isSms, isMobile);
                        }
                        break;
                }
                base.CloseConn();
                Response.Redirect(url);
            }
        }
 

    }
}
